package core.traits;

import core.Named;

/**
 * Traits are special key-value objects
 * 
 * A trait is an identifiable key-value pair. Traits are used by players to keep
 * track of various player state. A trait is the same as a second trait so long
 * as it has the same name.
 * 
 * @version 1.0
 * @author Alexander Schearer <aas11@duke.edu>
 */
public class Trait implements Named<Trait> {

	private String myName;

	private int myValue;
	
	public Trait(String name)
	{
		myName = name;
		myValue = 0;
	}

	public Trait(String name, int value) {
		this(name);
		myValue = value;
	}

	/**
	 * Update the trait's amount by the given value
	 * 
	 * @param amount
	 */
	public void update(int amount) {
		myValue += amount;
	}

	/**
	 * Retrieve the trait's name
	 * 
	 * @return
	 */
	public String getName() {
		return myName;
	}

	/**
	 * Retrieve the trait's value
	 * 
	 * @return
	 */
	public int getValue() {
		return myValue;
	}

	/**
	 * Convenience method which returns the trait's name and value as a string
	 */
	@Override
	public String toString() {
		return myName + ": " + myValue;
	}

	public int compareTo(Trait i) {
		return myName.compareTo(i.getName());
	}

	public boolean equals(Trait i) {
		return myName.equals(i.getName());
	}
}
